/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author edgar
 */
@Entity
@Table(name = "compras_detalle")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ComprasDetalle.findAll", query = "SELECT c FROM ComprasDetalle c"),
    @NamedQuery(name = "ComprasDetalle.findByNroFactura", query = "SELECT c FROM ComprasDetalle c WHERE c.comprasDetallePK.nroFactura = :nroFactura"),
    @NamedQuery(name = "ComprasDetalle.findByCodProveedor", query = "SELECT c FROM ComprasDetalle c WHERE c.comprasDetallePK.codProveedor = :codProveedor"),
    @NamedQuery(name = "ComprasDetalle.findByNroLinea", query = "SELECT c FROM ComprasDetalle c WHERE c.comprasDetallePK.nroLinea = :nroLinea"),
    @NamedQuery(name = "ComprasDetalle.findByCantidad", query = "SELECT c FROM ComprasDetalle c WHERE c.cantidad = :cantidad"),
    @NamedQuery(name = "ComprasDetalle.findByCosto", query = "SELECT c FROM ComprasDetalle c WHERE c.costo = :costo")})
public class ComprasDetalle implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ComprasDetallePK comprasDetallePK;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Column(name = "cantidad")
    private Float cantidad;
    @Column(name = "costo")
    private Integer costo;
    @JoinColumns({
        @JoinColumn(name = "nro_factura", referencedColumnName = "nro_factura", insertable = false, updatable = false),
        @JoinColumn(name = "cod_proveedor", referencedColumnName = "cod_proveedor", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private ComprasCabecera comprasCabecera;
    @JoinColumn(name = "cod_articulo", referencedColumnName = "cod_articulo")
    @ManyToOne
    private Articulos codArticulo;

    public ComprasDetalle() {
    }

    public ComprasDetalle(ComprasDetallePK comprasDetallePK) {
        this.comprasDetallePK = comprasDetallePK;
    }

    public ComprasDetalle(int nroFactura, int codProveedor, int nroLinea) {
        this.comprasDetallePK = new ComprasDetallePK(nroFactura, codProveedor, nroLinea);
    }

    public ComprasDetallePK getComprasDetallePK() {
        return comprasDetallePK;
    }

    public void setComprasDetallePK(ComprasDetallePK comprasDetallePK) {
        this.comprasDetallePK = comprasDetallePK;
    }

    public Float getCantidad() {
        return cantidad;
    }

    public void setCantidad(Float cantidad) {
        this.cantidad = cantidad;
    }

    public Integer getCosto() {
        return costo;
    }

    public void setCosto(Integer costo) {
        this.costo = costo;
    }

    public ComprasCabecera getComprasCabecera() {
        return comprasCabecera;
    }

    public void setComprasCabecera(ComprasCabecera comprasCabecera) {
        this.comprasCabecera = comprasCabecera;
    }

    public Articulos getCodArticulo() {
        return codArticulo;
    }

    public void setCodArticulo(Articulos codArticulo) {
        this.codArticulo = codArticulo;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (comprasDetallePK != null ? comprasDetallePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ComprasDetalle)) {
            return false;
        }
        ComprasDetalle other = (ComprasDetalle) object;
        if ((this.comprasDetallePK == null && other.comprasDetallePK != null) || (this.comprasDetallePK != null && !this.comprasDetallePK.equals(other.comprasDetallePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.ComprasDetalle[ comprasDetallePK=" + comprasDetallePK + " ]";
    }
    
}
